<?php

    class Utils
    {
        /**
         * ����������� ������ �������� � ������� ��������
         *
         * @param $objArr array
         * @return array
         */
        public static function convertArticleToArray( $objArr )
        {
            $isSetData = isset( $objArr ) && !empty( $objArr );
            if ( !$isSetData )
            {
                return null;
            }

            $result = array();
            foreach ( $objArr as $key => $item )
            {
                $result[$key]["title"]          = $item->title;
                $result[$key]["description"]    = $item->description;
                $result[$key]["path"]           = $item->path;
            }

            return $result;
        }

        /**
         * ������� ����� � ����
         *
         * @param array $fileNames
         * @return string
         */
        public static function getMergedFilesContent( $fileNames )
        {
            $result = "";
            if ( !empty( $fileNames ) )
            {
                foreach ( $fileNames as $fileName )
                {
                    if ( file_exists( $fileName ) )
                    {
                        $result .= file_get_contents( $fileName ) . "\n";
                    }
                }
            }

            return $result;
        }

        public static function NormalizeResourcesPath( $content )
        {
            $contentServerUrl = Core::Config()->server_url->content_server_url;
            return preg_replace( "/(\/images\/[^\"\'])/", $contentServerUrl . "$1", $content );
        }
    }

?>